package io.openkunlun.javadsl.client;

import com.google.protobuf.Empty;
import io.openkunlun.javadsl.v1.DaprCommonProtos;
import io.openkunlun.javadsl.v1.DaprProtos;
import lombok.Builder;
import lombok.Data;

import java.util.Map;

@Data
@Builder
public final class DeleteStateAction implements DaprAction<Empty> {

    private String storeName;
    private String key;
    private String etag;
    private Map<String, String> metadata;

    /**
     * @param daprClient
     * @return
     */
    @Override
    public Empty invoke(DaprClient daprClient) throws Exception {
        return daprClient.deleteState(DaprProtos.DeleteStateRequest
                .newBuilder()
                .setStoreName(storeName)
                .setKey(key)
                .setEtag(DaprCommonProtos.Etag.newBuilder().setValue(etag).build())
                .putAllMetadata(metadata)
                .build());
    }

}
